﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Convertor.Interface
{
    /// <summary>
    /// 读取配置控件窗口接口
    /// </summary>
    public interface IPluginConfigLoader
    {
        /// <summary>
        /// 读取配置控件窗口接口
        /// </summary>
        PluginConfigLoader Loader { get; set; }
    }
    /// <summary>
    /// 生成读取配置控件窗口委托
    /// </summary>
    /// <param name="pluginContent"></param>
    /// <param name="plugin"></param>
    /// <returns></returns>
    public delegate System.Windows.Window DelegateGenerateLoader(IPluginItem pluginContent, object plugin);

    /// <summary>
    /// 读取配置控件窗口类
    /// </summary>
    public class PluginConfigLoader
    {
        /// <summary>
        /// 读取页面
        /// </summary>
        public System.Windows.Window Loader { get; set; }
        /// <summary>
        /// 插件内容
        /// </summary>
        public IPluginItem PluginContent { get; set; }
        /// <summary>
        /// 插件源
        /// </summary>
        public object Plugin { get; set; }
        /// <summary>
        /// 生成读取配置控件窗口委托
        /// </summary>
        public DelegateGenerateLoader GenerateLoader { get; set; }
        /// <summary>
        /// 打开读取页面
        /// </summary>
        /// <returns></returns>
        public bool? ShowDialog()
        {
            if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
            {
                Loader = GenerateLoader(PluginContent, Plugin);
                return Loader.ShowDialog();
            }
            else
            {
                return false;
            }
        }
    }
}
